package com.cos.openapi.services.impl;

import com.cos.openapi.common.ResponseResult;
import com.cos.openapi.common.ResultTable;
import com.cos.openapi.dao.CustomerMapper;
import com.cos.openapi.entity.Customer;
import com.cos.openapi.services.CustomerServices;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.image.CropImageFilter;
import java.util.List;

/**
 * @author: COS
 * @time: 2021/11/25 16:12
 * @description:
 */
@Service
public class CustomerServicesImpl implements CustomerServices {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public ResultTable table(Integer page, Integer limit, String name, Integer state) {
        PageHelper.startPage(page, limit);
        List<Customer> customerList = customerMapper.getTable(name, state);
        PageInfo pi = new PageInfo(customerList);
        return new ResultTable(0, "", (int) pi.getTotal(), pi.getList());
    }

    @Override
    public ResponseResult del(Integer[] ids) {

        int i = customerMapper.del(ids);
        if (i > 0) {
            return ResponseResult.getSuccess();
        }
        return ResponseResult.getFail("错了");
    }

    @Override
    public ResponseResult update(Customer c) {
        if (c != null) {

            int i = customerMapper.updateByPrimaryKeyWithBLOBs(c);
            if (i > 0) {
                return ResponseResult.getSuccess();
            }
        }
        return ResponseResult.getFail("错了");
    }

    @Override
    public ResponseResult add(Customer c) {
        if (c != null) {

            int i = customerMapper.insertSelective(c);
            if (i > 0) {
                return ResponseResult.getSuccess();
            }
        }
        return ResponseResult.getFail("错了");
    }
}
